package main

import (
	"fmt"
	"math"
	"strconv"
	"time"
)

type TwoInts struct {
	a int
	b int
}

func (tn *TwoInts) String() string {
	return "(" + strconv.Itoa(tn.a) + "/" + strconv.Itoa(tn.b) + ")"
}

func (tn *TwoInts) AddThem() int {
	return tn.a + tn.b
}

func (tn *TwoInts) AddToParam(param int) int {
	return tn.a + tn.b + param
}

type IntVector []int

func (v IntVector) Sum() (s int) {
	for _, x := range v {
		s += x
	}
	return
}

type myTime struct {
	time.Time //anonymous field
}

func (t myTime) first3Chars() string {
	return t.Time.String()[0:3]
}

type Point struct {
	x, y float64
}

func (p *Point) Abs() float64 {
	return math.Sqrt(p.x*p.x + p.y*p.y)
}

type NamedPoint struct {
	Point
	name string
}

func main() {
	tn := TwoInts{10, 20}
	fmt.Println(tn.AddThem(), tn.AddToParam(20))
	fmt.Printf("two1 is: %v\n", tn)
	fmt.Println("two1 is:", tn)
	fmt.Printf("two1 is: %T\n", tn)
	fmt.Printf("two1 is: %#v\n", tn)

	fmt.Println(IntVector{1, 2, 3}.Sum())

	n := NamedPoint{name: "Jay", Point: Point{1, 2}}
	fmt.Println(n.Abs())
	n1 := &NamedPoint{name: "Jerry", Point: Point{3, 5}}
	fmt.Println(n1.Abs())
}
